<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        const arr = [1, 2, 3, 4, 5, 6]
        const arr1 = arr.filter(item => item % 2 === 0)
        console.log(arr, arr1);

        // 自定义filter
        function filter(arr, fn) {
            const result = []

            for(const item of arr) {
                if (fn(item)) {
                    result.push(item)
                }
            }
            return result
        }

        console.log(filter([1, 2, 3, 4, 5, 6], item => item % 2 === 1)); // 1 3 5
    </script>
</body>
</html>